{include file="Public:header" /}

		<div class="bar bar-nav">
			<h1 class="title">绑定手机</h1>
			<i class="icon icon-left" onclick="window.history.go(-1);"></i>
		</div>
		<div class="content">
		<form action="{:U('Index/applyUser')}" method="post" id="apply_form">
			<div class="list-block join">
		    <ul>
		      <li>
		        <div class="item-content">
		          <div class="item-media"><i class="icon icon-form-password"></i></div>
		          <div class="item-inner">
		            <div class="item-title label">手机号码：</div>
		            <div class="item-input">
		              <input type="tel" name="phone_number" value="" placeholder="手机号码" style="width: 110px;float: left;"><button type="button" id="getCodeBtn" class="button pull-right;" style="margin-top: 10px;padding:0 5px;font-size:12px;">发送验证码</button>
		            </div>
		          </div>
		        </div>
		      </li>
		      
		       <li>
		        <div class="item-content">
		          <div class="item-media"><i class="icon icon-form-gender"></i></div>
		          <div class="item-inner">
		            <div class="item-title label">验证码：</div>
		            <div class="item-input">
		              <input type="text" name="code" placeholder="验证码">
		            </div>
		          </div>
		        </div>
		      </li>
		      
		    </ul>
		  </div>
		  <div class="content-block">
		    <div class="row">
		      <div class="col-100 text-center"><button style="width:100%;" class="button button-big button-fill button-danger">提交</button></div>
		    </div>
		  </div>
		  </form>
		</div>

{include file="Public:footer" /}

<script>
	var myreg = /(1[3-9]\d{9})$/;
	var true_or_false = true;
	$("#apply_form").submit(function(){
		 var code = $("input[name='code']").val();
		 if($("input[name='phone_number']").val() == ''){
			 Zepto.toast('请填写手机号码！', 2000, 'success top');
			 return false;
		 }
		 if(!myreg.test($("input[name='phone_number']").val())){
			 Zepto.toast('手机格式不正确！', 2000, 'success top');
			 return false;
		 }
		 if(code == ''){
			 Zepto.toast('请填写验证码！', 2000, 'success top');
			 return false;
		 }
		 //检验验证码
		 $.ajax({
	 			type : "get",
	 			//url:"/index.php?m=Mobile&c=User&a=collect_list&is_ajax=1&p="+page,//+tab,			
	 			url:"{:U('Index/check_code')}",//+tab,
	 			data : {'code': code},// 你的formid 搜索表单 序列化提交
	 			dataType : 'json',
	 			async: false,
	 			success: function(data){
	 				if(data.status == 1){
	 					true_or_false = true;
	 				}else if(data.status == 2){
	 					Zepto.alert(''+data.message+'');
	 					true_or_false =  false;
	 					//Zepto.toast(''+data.message+'', 2000, 'success top');
	 				}
	 			}
	 		}); 
		 return true_or_false;
	});
	
	
	//倒计时
	  var bt01 = document.getElementById("getCodeBtn");
	  bt01.onclick = function() {
	  var phone_number = $("input[name='phone_number']").val();
		 if(phone_number == ''){
			 Zepto.toast('请填写手机号码！', 2000, 'success top');
			 return false;
		 }
		 if(!myreg.test(phone_number)){
			 Zepto.toast('手机格式不正确！', 2000, 'success top');
			 return false;
		 }
		//发送短信
		send_sms(phone_number); 
	    bt01.disabled = true;  //当点击后倒计时时候不能点击此按钮
	    var time = 60;  //倒计时5秒
	    var timer = setInterval(fun1, 1000);  //设置定时器
	    function fun1() {
	      time--;
	      if(time >= 0) {
	        bt01.innerHTML = time + "s后重新发送";
	      }else{
	        bt01.innerHTML = "重新发送";
	        bt01.disabled = false;  //倒计时结束能够重新点击发送的按钮
	        clearTimeout(timer);  //清除定时器
	        time = 60;  //设置循环重新开始条件
	      }
	    }
	  } 
	
	 /* $("#getCodeBtn").click(function(){
		 that = $(this);
		 var phone_number = $("input[name='phone_number']").val();
		 if(phone_number == ''){
			 Zepto.toast('请填写手机号码！', 2000, 'success top');
			 return false;
		 }
		 if(!myreg.test(phone_number)){
			 Zepto.toast('手机格式不正确！', 2000, 'success top');
			 return false;
		 }
		 that.attr('disabled',true);  //当点击后倒计时时候不能点击此按钮
		 var time = 60;  //倒计时60秒
		 var timer = setInterval(fun1, 1000);  //设置定时器
		 function fun1() {
		      time--;
		      if(time >= 0) {
		    	  that.text(time + "s后重新发送");
		      }else{
		    	that.text = "重新发送验证码";
		    	that.attr('disabled',false);  //倒计时结束能够重新点击发送的按钮
		        clearTimeout(timer);  //清除定时器
		        time = 60;  //设置循环重新开始条件
		      }
		    }
	});  */
	
	//发送短信
	function send_sms(phone_number){
		 $.ajax({
	 			type : "get",
	 			//url:"/index.php?m=Mobile&c=User&a=collect_list&is_ajax=1&p="+page,//+tab,			
	 			url:"{:U('Index/send_sms')}",//+tab,
	 			data : {'phone_number':phone_number},// 你的formid 搜索表单 序列化提交
	 			dataType : 'json',
	 			success: function(data){
	 				if(data.status == 1){
	 					return true;
	 				}else{
	 					Zepto.alert(''+data.message+'');
	 					//Zepto.toast(''+data.message+'', 2000, 'success top');
	 					return false;
	 				}
	 			}
	 		});  
	}
	
	//检查验证码
	 function check_code(code, true_or_false){
		 $.ajax({
	 			type : "get",
	 			//url:"/index.php?m=Mobile&c=User&a=collect_list&is_ajax=1&p="+page,//+tab,			
	 			url:"{:U('Index/check_code')}",//+tab,
	 			data : {'code': code},// 你的formid 搜索表单 序列化提交
	 			dataType : 'json',
	 			async: false,
	 			success: function(data){
	 				if(data.status == 1){
	 					true_or_false = true;
	 				}else if(data.status == 2){
	 					true_or_false = false;
	 					Zepto.alert(''+data.message+'');
	 					//Zepto.toast(''+data.message+'', 2000, 'success top');
	 				}
	 			}
	 		});
	 }
</script>